home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.cs.arizona.edu
/
ftp.cs.arizona.edu.tar
/
ftp.cs.arizona.edu
/
icon
/
newsgrp
/
group93c.txt
/
000042_icon-group-sender _Tue Sep 7 00:30:31 1993.msg
< prev
next >
Wrap
Internet Message Format
|
1994-02-02
|
2KB
Received: from owl.CS.Arizona.EDU by cheltenham.cs.arizona.edu; Tue, 7 Sep 1993 08:22:43 MST
Received: by owl.cs.arizona.edu; Tue, 7 Sep 1993 08:22:42 MST
Date: Tue, 7 Sep 93 00:30:31 -0700
From: "Nevin Jerome Liber" <nevin>
Message-Id: <9309070730.AA18987@caslon.CS.Arizona.EDU>
To: icon-group@cs.arizona.edu
Subject: Re: return results from procedure
Status: R
Errors-To: icon-group-errors@cs.arizona.edu
rjhare@festival.ed.ac.uk (Roger Hare) writes:
> I've been using Icon for seberal years now, but recently I stumbled across a
> 'problem' for the fist time - I wanted to return more than one result from a
> procedure (yup - strange to relate, after several years I had never needed to
> do this before).
> What I want to know is "what is the 'best' way to return several results from
> a procedure?'.
What I find most idiomatic for returning multiple results from a
procedure is to use generators. The called routine would look like:
procedure MyProcedure()
...
suspend xResult1
...
suspend xResult2
...
...
suspend xResultN
...
end
And the caller would look like:
...
every xElement := MyProcedure() do {
ProcessElement(xElement)
}
...
This approach is space-efficient (if the data is being used in a FIFO
order, only one element has to be in existence at a given time) and
very flexible. The caller, and not the callee can determine what type
of data structure to keep the elements in (unlike in more traditional
languages like C and Pascal). For example, if I needed to build both an
ordered list and a set, I could write the caller like:
LList := list()
SSet := set()
every xElement := MyProcedure() do {
put(LList, xElement)
insert(SSet, xElement)
}
___
Nevin ":-)" Liber nevin@cs.arizona.edu (602) 293-2799